package _18_剑指OfferII;

public class _034_剑指OfferII外星语言是否排序 {

    // 字典排序，也就是内置函数中正常的排序结果，string字符串排序，比较每个字符大小
    public boolean isAlienSorted(String[] words, String order) {
        int wordsLen = words.length;
        // 先将字符串转换为order的排序字符
        for (int i = 0; i < wordsLen; i++) {
            StringBuilder sb = new StringBuilder();
            for (char s: words[i].toCharArray()) {
                sb.append((char) (order.indexOf(s) + 'a'));
            }
            words[i] = sb.toString();
        }

        for (int i = 1; i < wordsLen; i++) {
            if (words[i].compareTo(words[i - 1]) < 0) return false;
        }
        return true;
    }

}
